package testing.src.vineet.java.code.probs;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import testing.src.vineet.java.code.node.Node;
import testing.src.vineet.java.code.stack.MyStack;
import testing.src.vineet.java.code.stack.Stack;

enum Paranthesis
{
	left("("),right(")"),middleLeft("{"),middleRight("}"),bigLeft("["),bigRight("]");
	
	private String val;
	
	Paranthesis(String val)
	{
		this.val = val;
	}
	
	
}

public class CheckParanthesis 
{
	public static final String left="{";
	public static final String right="}";
	public static final String smallLeft="(";
	public static final String smallRight=")";
	public static final String bigLeft="[";
	public static final String bigRight="]";
	
	public static void main(String argv[])
	{
		System.out.println("Enter a expr");
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String expr = br.readLine();
			String[] ExprArr = expr.split("");
			
			System.out.println(checkParanthesis(ExprArr));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	/**
	 * Example: check a mathematical expression.
	 */
	public static boolean checkParanthesis(String[] expr)
	{
		if(null == expr || expr.length > 0)
			return true;
		
		Stack<String> s = new MyStack<String>();
		for(int i=0,size = expr.length;i < size; i++)
		{
			if(expr.equals(left)||expr.equals(smallLeft)||expr.equals(bigLeft))
			{
				s.push(left);
			}
			else
			{
				Node<String> p = s.pop();
				if(null == p)
					return false;
				
				
			}
		}
		return true;
	}
}
